package com.zdp.provider.Command;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;

/**
 * 类描述: 使用代码的方式实现降级处理，继承 HystrixCommand
 *
 * @author ZhhengDP
 * @since 2021/8/20
 */
public class FallBackFailure extends HystrixCommand<String> {

    private String name;

    public FallBackFailure(String name){
        super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"));
        this.name = name;
    }

    /**
     * 具体的业务逻辑
     * @return
     * @throws Exception
     */
    @Override
    protected String run() throws Exception {
        System.out.println("业务逻辑");
        int i = 1/0;
        System.out.println("业务逻辑成功执行完毕");
        return "成功";
    }

    /**
     * 服务降级处理逻辑
     * @return
     */
    @Override
    protected String getFallback() {
        System.out.println("业务逻辑执行失败，进入降级处理");
        return "降级处理";
    }
}
